<?php

namespace app\model;

use think\facade\Db;
use think\Model;

class InnerTestUserModel extends Model {

    protected $table ="inner_test_user";

    protected $pk = 'id';


    /*
   * 获取total
   * */
    public function getTotal($where=[]){
        return Db::name($this->table)->where($where)->count();
    }


    /*
     * 获取list
     * */
    public function getList($where=[],$page = null,$limit = null,$orderField = null,$orderType = "ASC"){

        $obj =  Db::name($this->table)->field($this->pk)->where($where);

        if(!empty($page) && !empty($limit)){
            $obj = $obj->page($page, $limit);
        }

        if(!empty($orderField) && !empty($orderType)){
            $obj = $obj->order($orderField, $orderType);
        }

        $list = $obj->select();

        if($list){
            $return = [];
            foreach($list as $item){
                $return[] = $this->getInfo($item[$this->pk]);
            }
            return $return;
        }
        return [];
    }



    public function getInfo($id){
        return Db::name($this->table)->find($id);
    }



    /*
     * 检查用户在不在测试白名单
     * */
    public function isWhiteUser($uid){

        $where =[];
        $where[] = ['uid','=',$uid];
        $where[] = ['accept_status','=',1];
        return Db::name($this->table)->where($where)->find();

    }



    public function updateOne($id,$data){
        return Db::name($this->table)->where("id",$id)->update($data);
    }

}